package org.yx.service.sqcm.view_defective_code;

import org.dbist.dml.Page;
import org.dbist.dml.Query;
import org.yx.models.SqcmDftCod;
import org.yx.utils.BaseService;

import com.xiaoleilu.hutool.util.StrUtil;

/**
 * 查询不良代码定义
 * 
 * @author zxw
 * @since 2019/05/30
 **/
public class SqcmViewDefectiveCodeService extends BaseService {
	public SqcmViewDefectiveCodeOut viewDefectiveCode(SqcmViewDefectiveCodeIn in) throws Exception {
		Query query = new Query(in.getPageIndex(), in.getPageSize());
		query.addFilter("orgCode", in.getUserOrgCode());
		query.addFilter("status", 'N');
		if (StrUtil.isNotBlank(in.getFirstLevelCode())) {
			query.addFilter("firstLevelCode", in.getFirstLevelCode());
		}
		if (StrUtil.isNotBlank(in.getSecondLevelCode())) {
			query.addFilter("secondLevelCode", in.getSecondLevelCode());
		}
		if (StrUtil.isNotBlank(in.getThirdLevelCode())) {
			query.addFilter("thirdLevelCode", in.getThirdLevelCode());
		}

		Page<SqcmDftCod> dftPage = selectPage(SqcmDftCod.class, query);

		SqcmViewDefectiveCodeOut out = new SqcmViewDefectiveCodeOut();
		out.setCodeList(dftPage.getList());
		out.setTotal(dftPage.getTotalSize());

		return out;
	}
}